import 'package:t3_data_service/biz_data_source/map/address/poi_search/poi_search.dart';
import 'package:t3_data_service/data_provider/live_location/t3_live_location_provider.dart';

T3POILocation $T3POILocationDecode(dynamic json) {
  var location = T3POILocation.fromJson(json);
  if (location != null) {
    return location;
  }
  var liveLocation = T3LiveLocationProvider.instance.liveLocation;
  return T3POILocation(adCode: liveLocation?.adCode ?? '', cityName: liveLocation?.city ?? '',
      coordinate: LatLng(location?.coordinate.latitude ?? 0, location?.coordinate.longitude ?? 0));
}

List<T3EntryOptions> $T3EntryOptionsEnumDecode(int? value) {
  if (value == 1) {
    return [T3EntryOptions.homeAndCompany];
  }
  if (value == 2) {
    return [T3EntryOptions.map];
  }
  if (value == 3) {
    return [T3EntryOptions.homeAndCompany, T3EntryOptions.map];
  }
  return [];
}

/// 光标位置
/// 添加途经点：newMidway
/// 修改行程：firstPoi
/// 修改终点：endPoi
enum CursorLocation {
  /// 新增途径点，且为光标位置
  newMidway,
  /// 第一个为光标位置
  firstPoi,
  /// 终点为光标位置
  endPoi;

  static CursorLocation fromJson(String? json) {
    if (json == 'newMidway') {
      return CursorLocation.newMidway;
    }
    if (json == 'firstPoi') {
      return CursorLocation.firstPoi;
    }
    if (json == 'endPoi') {
      return CursorLocation.endPoi;
    }
    return CursorLocation.endPoi;
  }
}


/// 进入图选的类型
/// common: 点击图选按钮
/// multiPoint：点击多下车点
/// confusion：点击易混淆的点
/// fence: 地理围栏的点
enum T3MapSelectMode {
  common(0),
  multiPoint(1),
  confusion(2),
  fence(3);

  final int value;
  const T3MapSelectMode(this.value);

  static T3MapSelectMode fromJson(int? value) {
    if (value == 1) {
      return T3MapSelectMode.multiPoint;
    }
    if (value == 2) {
      return T3MapSelectMode.confusion;
    }
    if (value == 1) {
      return T3MapSelectMode.fence;
    }
    return T3MapSelectMode.common;
  }
}

enum CheckInitType {
  auto;

  static CheckInitType? fromJson(String? value) {
    if (value == 'auto') {
      return CheckInitType.auto;
    }
    return null;
  }
}

enum MapSpotConfigType {
  /// 逆向围栏
  invalidFence(0),
  /// 围栏
  fence(1),
  /// T3点
  personalEnd(2),
  personal(3),
  /// 自动驾驶吸附点
  autopilot(4);

  final int value;
  const MapSpotConfigType(this.value);

  static MapSpotConfigType? fromJson(int? value) {
    if (value == 1) {
      return MapSpotConfigType.invalidFence;
    }
    if (value == 2) {
      return MapSpotConfigType.fence;
    }
    if (value == 3) {
      return MapSpotConfigType.personalEnd;
    }
    if (value == 4) {
      return MapSpotConfigType.personal;
    }
    if (value == 5) {
      return MapSpotConfigType.autopilot;
    }
    return null;
  }
}

/// 页面如何消失
enum MapDisappearMode {
  pop,
  dismiss;

  static MapDisappearMode? fromJson(String? value) {
    if (value == 'pop') {
      return MapDisappearMode.pop;
    }
    if (value == 'dismiss') {
      return MapDisappearMode.dismiss;
    }
    return null;
  }
}

/// 1.图选 2.搜索列表尾部图选 3.确认下车点图选 4.易混图选
enum T3MapSelectSource {
  normal,
  footerView,
  confirm,
  confusion;

  static T3MapSelectSource? fromJson(String? value) {
    if (value == 'normal') {
      return T3MapSelectSource.normal;
    }
    if (value == 'footerView') {
      return T3MapSelectSource.footerView;
    }
    if (value == 'confirm') {
      return T3MapSelectSource.confirm;
    }
    if (value == 'confusion') {
      return T3MapSelectSource.confusion;
    }
    return null;
  }
}